package com.eshidai.simple_springboot.web;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.eshidai.simple_springboot.exception.MyException;

@Controller
public class HelloController {
	
	@Value("${com.eshidai.simple_springboot.number}") private Integer num;
	
	
	@RequestMapping("/hello")
	public String hello() throws Exception {
		return "hello";
	}
	
	@RequestMapping("/login")
	public String login() throws Exception {
		return "login";
	}
	
	@RequestMapping("/json")
	public String json() throws MyException {
		throw new MyException("自定义错误");
	}
	
	@RequestMapping(value="/index",method=RequestMethod.POST)
	public String index(@RequestParam String username, @RequestParam String password) throws Exception {
		ModelMap map = new ModelMap();
		map.addAttribute("host",num);
		return "index";
	}
}
